
package com.ifcar.app.view;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;

public class CommentToolsPopup extends MyPopupWindow {

    private Object mTag;

    private OnClickListener mOnClickListener;
    
    private boolean mHided;

    public CommentToolsPopup(Context context) {
        super(context, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        setOutsideTouchable(true);
        setFocusable(false);
    }

    public void setOnClickListener(OnClickListener listener, int[] clickIds) {
        mOnClickListener = listener;
        View contentView = getContentView();
        if (contentView != null) {
            if (clickIds != null && clickIds.length > 0) {
                for (int id : clickIds) {
                    View v = contentView.findViewById(id);
                    v.setOnClickListener(mOnClickListener);
                }
            }
        }
    }

    public void setTag(Object tag) {
        mTag = tag;
    }

    public Object getTag() {
        return mTag;
    }
    
    public boolean isHide() {
        return mHided;
    }

    @Override
    public void dismiss() {
        mTag = null;
        mHided = false;
        super.dismiss();
        if (getContentView() != null) {
            getContentView().setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void onOutSideTouched(MotionEvent event) {
        if (!mHided) {
            mHided = true;
            if (getContentView() != null) {
                getContentView().setVisibility(View.INVISIBLE);
            }
            return;
        }
        super.onOutSideTouched(event);
    }

    
}
